package com.ruoyi.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.domain.*;
import com.ruoyi.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.service.IZhwyAdvancedepositService;

/**
 * 预存款信息Service业务层处理
 * 
 * @author liuzhiqiang
 * @date 2024-05-07
 */
@Service
public class ZhwyAdvancedepositServiceImpl implements IZhwyAdvancedepositService 
{
    @Autowired
    private ZhwyAdvancedepositMapper zhwyAdvancedepositMapper;
    @Autowired
    private ZhwyChargeitemMapper zhwyChargeitemMapper;
    @Autowired
    private ZhwyPaymentmethodMapper zhwyPaymentmethodMapper;
    @Autowired
    private ZhwyShopsMapper zhwyShopsMapper;
    @Autowired
    private ZhwyBuildingMapper zhwyBuildingMapper;
    @Autowired
    private ZhwyDowntownMapper zhwyDowntownMapper;

    /**
     * 查询预存款信息
     * 
     * @param id 预存款信息主键
     * @return 预存款信息
     */
    @Override
    public ZhwyAdvancedeposit selectZhwyAdvancedepositById(Long id)
    {
        return zhwyAdvancedepositMapper.selectZhwyAdvancedepositById(id);
    }

    /**
     * 查询预存款信息列表
     * 
     * @param zhwyAdvancedeposit 预存款信息
     * @return 预存款信息
     */
    @Override
    public List<ZhwyAdvancedeposit> selectZhwyAdvancedepositList(ZhwyAdvancedeposit zhwyAdvancedeposit)
    {
        List<ZhwyAdvancedeposit> zhwyAdvancedeposits = zhwyAdvancedepositMapper.selectZhwyAdvancedepositList(zhwyAdvancedeposit);
        for(ZhwyAdvancedeposit zh:zhwyAdvancedeposits){
            //获取关联商铺
            if(zh.getShopsId()!=null){
                ZhwyShops zhwyShops = zhwyShopsMapper.selectZhwyShopsById(zh.getShopsId());
                zh.setShopname(zhwyShops.getCode());
            }



            //获取关联收款项目
            if(zh.getChargeitemId()!=null){
                ZhwyChargeitem zhwyChargeitem = zhwyChargeitemMapper.selectZhwyChargeitemById(zh.getChargeitemId());
                zh.setChargeitemName(zhwyChargeitem.getName());
            }

            //获取支付方式
            if(zh.getPayId()!=null){
                ZhwyPaymentmethod zhwyPaymentmethod = zhwyPaymentmethodMapper.selectZhwyPaymentmethodById(zh.getPayId());
                zh.setPayName(zhwyPaymentmethod.getName());
            }

            //获取退款方式
            if(zh.getRefundId()!=null){
            ZhwyPaymentmethod zhwyPaymentmethod1 = zhwyPaymentmethodMapper.selectZhwyPaymentmethodById(zh.getRefundId());
                zh.setPayName(zhwyPaymentmethod1.getName());
            }

        }
        return zhwyAdvancedeposits;
    }

    /**
     * 新增预存款信息
     * 
     * @param zhwyAdvancedeposit 预存款信息
     * @return 结果
     */
    @Override
    public int insertZhwyAdvancedeposit(ZhwyAdvancedeposit zhwyAdvancedeposit)
    {
        String s= String.valueOf(UUID.randomUUID());
        zhwyAdvancedeposit.setPayNo(s);
        return zhwyAdvancedepositMapper.insertZhwyAdvancedeposit(zhwyAdvancedeposit);
    }

    /**
     * 修改预存款信息
     * 
     * @param zhwyAdvancedeposit 预存款信息
     * @return 结果
     */
    @Override
    public int updateZhwyAdvancedeposit(ZhwyAdvancedeposit zhwyAdvancedeposit)
    {
        return zhwyAdvancedepositMapper.updateZhwyAdvancedeposit(zhwyAdvancedeposit);
    }

    /**
     * 批量删除预存款信息
     * 
     * @param ids 需要删除的预存款信息主键
     * @return 结果
     */
    @Override
    public int deleteZhwyAdvancedepositByIds(Long[] ids)
    {
        return zhwyAdvancedepositMapper.deleteZhwyAdvancedepositByIds(ids);
    }

    /**
     * 删除预存款信息信息
     * 
     * @param id 预存款信息主键
     * @return 结果
     */
    @Override
    public int deleteZhwyAdvancedepositById(Long id)
    {
        return zhwyAdvancedepositMapper.deleteZhwyAdvancedepositById(id);
    }
}
